package tech.aistar.corejava.day12;

import tech.aistar.corejava.day12.factory.ComparatorFactory;

import java.util.*;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/7/30
 * @Version: 1.0
 */
public class CollectionSortDemo {
    public static void main(String[] args) {
        Book b1 = new Book(1, "了不起的盖茨比", "忘了", 20.0);
        Book b2 = new Book(2, "刀锋", "毛姆", 35.0);
        Book b3 = new Book(3, "鬼吹灯", "天下霸唱", 296.0);
        Book b4 = new Book(4, "盗墓笔记", "南派三叔", 329.0);

        List<Book> list = new ArrayList<>();

        list.add(b1);
        list.add(b2);
        list.add(b3);
        list.add(b4);

//        Comparator<Book> c = new Comparator<Book>() {
//            @Override
//            public int compare(Book o1, Book o2) {
//                if(o1.getPrice()>o2.getPrice()){
//                    return 1;
//                }else if(o1.getPrice()<o2.getPrice()){
//                    return -1;
//                }else{
//                    return 0;
//                }
//            }
//        };
        //Comparator<Book> c = ComparatorFactory.getInstance(ComparatorFactory.NAME);
        Comparator<Book> c = ComparatorFactory.getInstance(ComparatorFactory.PRICE);

        Collections.sort(list,c);

        list.forEach(System.out::print);
    }
}
